<template>
  <div style="width: 100%">
    <div id="deawer">
      <v-tableTitle :btnConfig="btnConfig1"
                    @cancel="cancel"
                    @save="save"></v-tableTitle>
      <div class="detailBox">
        <v-details :inputConfig="inputConfig"
                   :detailData='inputData'
                   :rules="rules"
                   ref="input"
                   @pop="setdata"></v-details>
      </div>
      <div class="detailListBox">
        <v-detail ref="detail"></v-detail>
      </div>
    </div>
  </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import config from "../Config"
import skipMixin from "@/mixins/SkipMixin";
import tableTitle from "commons/TableTitle";
import bus from "../../../../../bus/bus";
import details from '@/components/commons/Detail'
import detail from "../details/Detail"

export default {
  name: "",
  mixins: [baseMixin, config, skipMixin],
  data () {
    return {
      dialogTableVisible: false,
      poUrl: "queryListOfPoModal/true/1/true/true/",
      lookUrl: "queryListOfTaskDetailModal/",
      routeData: {},
      inputData: {
        rtxchecklist: "",//品检单号
        rtxcheckdate: "",//检验日期
        rtxdept: "",//检验部门
        rtxchecker: "",//检验员
        rtxstandard: "",//检验标准
        rtxresult: "",//检验结果
        addwho: "",//创建人
        adddate: "",//创建时间
        editwho: "",//修改人
        editdate: "",//修改时间 
        rtxremark: "",//备注 
      },
      rules: {
      },
    };
  },
  computed: {
    btnConfig1 () {
      return [
        { label: this.$t('common.save'), certigier: !this.btnPermNameList.includes('WM010702'),  invalid: "save" },
        { label: this.$t('common.cancel'), certigier: !this.btnPermNameList.includes('WM010703'),  invalid: "cancel" },
      ]
    },
    inputConfig () {
      return [
        [
          {
            type: "input",
            label: this.$t('in.rtxchecklist'),
            disabled: true,
            props: "rtxchecklist"
          },
          {
            type: "date",
            label: this.$t('in.rtxcheckdate'),
            disabled: false,
            props: "rtxcheckdate"
          },
          {
            type: "input",
            label: this.$t('in.rtxdept'),
            disabled: false,
            props: "rtxdept"
          },
          {
            type: "input",
            label: this.$t('in.editwho'),
            disabled: false,
            props: "rtxchecker"
          },
        ],
        [
          {
            type: "select",
            label: this.$t('in.rtxstandard'),
            disabled: false,
            props: "rtxstandard",
            options: this.getOptions("codelkup/ACCEPTANCESTANDARD")
          },
          {
            type: "select",
            label: this.$t('in.rtxresult'),
            disabled: true,
            props: "rtxresult",
            options: this.getOptions("codelkup/RTXRESULT")
          },
          {
            type: "input",
            label: this.$t('app.createName'),
            disabled: true,
            props: "addwho"
          },
          {
            type: "date",
            label: this.$t('app.createDate'),
            disabled: true,
            props: "adddate"
          },
        ],
        [
          {
            type: "input",
            label: this.$t('app.updateName'),
            disabled: true,
            props: "editwho"
          },
          {
            type: "date",
            label: this.$t('app.updateDate'),
            disabled: true,
            props: "editdate"
          },
          {
            type: "textarea",
            label:  this.$t('app.remark'),
            disabled: false,
            props: "rtxremark"
          },
        ],
      ]
    },
  },
  created () {
  },
  methods: {
    setdata (data, id, close, listId) {
      this.choseFormData = data;//选中表格的一行,赋值给对象
      if (id == 0 && listId == 0) {
        this.inputData.receiptkey = data.receiptkey;
      } else if (id == 0 && listId == 1) {
        this.inputData.lineno = data.receiptlinenumber;
        this.inputData.sku = data.sku;
        this.inputData.descr = data.descr;
        this.inputData.uom = data.uom;
        this.inputData.qty = data.qtyexpected;
      }
      close(false);
    },
    //保存按钮
    async save () {

      let params = { ... this.inputData }
      if (this.$refs.detail.type === '1') {
        params.qcDetailList = [{ ...this.$refs.detail.detailData }]
      } else if (this.$refs.detail.type === '2') {
        params.qcTypeList = [{ ...this.$refs.detail.detailData }]
      } else if (this.$refs.detail.type === '3') {
        params.qcReportList = [{ ...this.$refs.detail.detailData }]
      }

      this.$api.post('/updateRtxQc', params).then(res => {
        
          this.$message.success(this.$t('app.saveMes'))
      })
    },
    //弹框取消
    cancel () {
      let routerName = JSON.parse(sessionStorage.getItem('routerName'));
      let num = -1;
      if (routerName) {
        num = routerName.indexOf("rtxqc");
      }
      if (num === -1) {
        this.$router.push({ name: "rtxqc" });
      } else {
        num = num - 0;
        routerName.splice(num, 1);
        sessionStorage.setItem('routerName', JSON.stringify(routerName));
        this.$router.push({ name: "home1" })
      }

    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.flag = data.newFlag;
      this.routeData = data.routeData;
    } else if (this.$store.state.newFlag) {
      this.flag = true;
    } else {
      this.routeData = this.$store.state.routeData
    }
    this.$api.get(`/queryRtxQcByCode/` + this.routeData.whseid + '/' + this.routeData.rtxchecklist).then(res => {
      
        this.inputData = res.bean
    });
  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    'v-details': details,
    "v-detail": detail,
  },

}
</script>

<style scoped>
</style>
